provider "alicloud" {
  profile = "default"
  version = "1.144.0"
  region = "cn-chengdu"
}

data "alicloud_log_projects" "example" {
  ids = ["datalab-1198585816170303-cn-chengdu"]
}

//output "first_log_project_id" {
//  value = data.alicloud_log_projects.example
//}
//
//data "alicloud_log_stores" "example" {
//  project = "datalab-1198585816170303-cn-chengdu"
//}

output "first_log_store_id" {
  value = data.alicloud_log_projects.example.ids.0
}

resource "alicloud_log_alert" "example" {
  project_name      = "datalab-1198585816170303-cn-chengdu"
  alert_name        = "tf-test-alert"
  alert_displayname = "tf-test-alert-displayname"
  condition         = "count > 100"
  dashboard         = "tf-test-dashboard"
  query_list {
    logstore    = "website_log"
    chart_title = "chart_title"
    start       = "-60s"
    end         = "20s"
    query       = "* AND aliyun"
  }
  notification_list {
    type        = "DingTalk"
    service_uri = "www.aliyun.com"
    content     = "alert content"
  }
}

//resource "alicloud_log_dashboard" "example" {
//  project_name   = "datalab-1198585816170303-cn-chengdu"
//  dashboard_name = "tf-dashboard"
//  char_list      = <<EOF
//  [
//    {
//      "title":"new_title",
//      "type":"map",
//      "search":{
//        "logstore":"tf-logstore",
//        "topic":"new_topic",
//        "query":"* | SELECT COUNT(host) as ct_name, COUNT(region) as ct_region, host,region GROUP BY host,region",
//        "start":"-86400s",
//        "end":"now"
//      },
//      "display":{
//        "xAxis":[
//          "ct_name"
//        ],
//        "yAxis":[
//          "ct_region"
//        ],
//        "xPos":0,
//        "yPos":0,
//        "width":10,
//        "height":12,
//        "displayName":"xixihaha911"
//      }
//    }
//  ]
//EOF
//}